package com.yjps.house.service;

import com.yjps.common.dao.AddressDao;
import com.yjps.common.model.Address;
import com.yjps.house.dao.BuildingDao;
import com.yjps.house.model.Building;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Jelly on 2015/8/25 0025.
 */
@Service
public class BuildingService {

    @Autowired
    BuildingDao buildingDao;

    @Autowired
    AddressDao addressDao;

    @Transactional
    public List<Building> getList() {
        String hql = "from Building b where b.valid=1";
        return buildingDao.find(hql);
    }

    @Transactional
    public void delete(int id) {
        Building building = (Building) buildingDao.get(id);
        buildingDao.invalid(building);

    }

    @Transactional
    public int add(Building building, int addressId) {

        building.setAddressId(addressId);

        return buildingDao.save(building);

    }

    @Transactional
    public int addAddress(Address address) {


        return addressDao.save(address);
    }
}
